// pages/storerecord/storerecord.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pointsTotal:0,
    list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.api.interface.gettasklist().then(res=>{
      if (res.data.code == 200) {
        console.log('res.data.data', res.data.data)
        let { currentList, completedList } = res.data.data;

        this.setData({
          list: currentList,
          listDone: completedList
        })
        console.log('this.data', this.data)
      }
    })
    this.get_score();
  },
  get_score(){
    let that = this;
    this.api.interface.integralMallContent().then(result => {
      if (result.data.data.remainPoint) {
        that.setData({
          pointsTotal: result.data.data.remainPoint,
        });
      }
    })
  },
  cli_exchange(){
    wx.navigateTo({
      url: '../store/store',
    });
  },
  goToUrl(e){
    let t = this;
    let {
      task
    } = e.currentTarget.dataset;
    if(task == "TASK_SCAN"){
      this.onScanTap()
    }else{//TASK_FULL_USER_INFO
      wx.navigateTo({ url: '../info/info' })
    }
  },
  // 扫一扫
  onScanTap() {
    const that = this;
    wx.requestSubscribeMessage({
      tmplIds: ['QVk5ycLHaIqtUSN651qTuL13SxXfTIIA6ek7z5cBA8E'],
      complete() {
        wx.scanCode({
          onlyFromCamera: true,
          success(res) {
            console.log('---d----- -- ->', res)
            if (!res.result) {
              wx.navigateTo({
                url: '/pages/isnotcorrect/isnotcorrect',
              })
              return false;
            }
            var qrcode = res.result;
            var code
            if (38 == qrcode.length) {
              code = qrcode.substring(26);
            } else if (43 == qrcode.length) {
              code = qrcode.substring(27);
            }
            // 如果新用户则先跳转授权页面
            if (!wx.getStorageSync('userinfo').nickName) {
              wx.setStorageSync('scancode', code)
              wx.navigateTo({
                url: '/pages/authorization/authorization?act=' + 1,
              })
            }
            that.setData({
              code: code
            });
            that.onSubmit(that);
          }
        });

      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})